<?php
declare (strict_types = 1);
namespace app\promotion\model;

use app\common\model\BaseModel;
use app\user\logic\user\Account;
use think\model\concern\SoftDelete;

/**
 * 砍价用户数据模型
 */
class PromotionBargainData extends BaseModel
{
    use softDelete;
    /**
     * 表名
     * @var string
     */
    protected $name = 'promotion_bargain_data';

    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id'                    => 'integer',
        'bargain_id'            => 'integer',
        'current_user_id'       => 'integer',
        'current_bargain_price' => 'float',
        'create_time'           => 'integer',
    ];

    /**
     * 当前用户查询范围
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-12
     * @param  [type]  $query           [description]
     * @param  integer $current_user_id [description]
     * @return [type]                   [description]
     */
    public function scopeCurrent($query, $current_user_id = 0)
    {
        $current_user_id = $current_user_id ?? request()->mid;
        $query->whereCurrentUserId($current_user_id);
    }

    /**
     * 用户头像名称关联
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-09
     * @param string $value [description]
     */
    public function userAvatarName()
    {
        return $this->belongsTo(Account::class, 'current_user_id')->with(['avatar_url'])->bind(['current_user_name' => 'nick_name', 'current_user_avatar_url' => 'avatar_url']);
    }

}
